<?php
class UserController extends Zend_Controller_Action{
	public function init(){
		$this->view->baseUrl = $this->_request->getBaseUrl();
		Zend_Loader::loadClass('User');
		Zend_Loader::loadClass('role');
		}
		
	function indexAction() 
    { 

		$this->view->title = 'plima管理系统';
		$this->render();
    } 
	
	function addAction(){
		Zend_Loader::loadClass('Zend_Filter_StripTags');
		$filter = new Zend_Filter_StripTags();
		$password = trim($filter->filter($this->_request->getPost('pwd1')));
		$password2 = trim($filter->filter($this->_request->getPost('pwd2')));
		if($password==$password2){
				$user=new User();
				$user->add($_POST);
				success("成功"); 
				exit;
	    		//$this->_redirect("index/index");
			}
		else{
			failure("两次密码不一致");
			}
	}
	
	function delAction(){
		$user=new User();
		$ids=$this->_request->getPost('id');		
		if($user->del($ids)){
			success($ids);
		}
		else{
			error("发生错误");
			}
		exit;
		}
	
	
	function delroleAction(){
		$role=new role();
		$ids=$this->_request->getPost('id');		
		if($role->del($ids)){
			success($ids);
		}
		else{
			error("发生错误");
			}
		exit;
		}
	
	function editAction(){
		if($this->_request->ispost()){
			$user=new User();
			$data=json_decode($_POST['data']);
			foreach($data as $item){
					$info=array(
								'id'		=> $item->u_id,
								'username'	=> $item->username,
								'realname'	=> $item->realname,
								'pwd1'		=> $item->pwd,
								'email'		=> $item->email,
								'role'		=> $item->role
								);
					
					//print_r($info);
				
					if($user->add($info)){
						success("OK");
						}
					else{
						failure("失败");
						}
				}
			}
		exit;
		}
	
}
?>